<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.cms.biz.category.CategoryHelper"%>
<%@page import="com.cms.menu.MenuHelper"%>
<%@page import="java.sql.*, java.util.*, com.cms.config.*, com.cms.facade.*,com.cms.util.*,com.cms.bean.*,com.cms.database.DBHelper"%>
<%@page import="org.apache.log4j.Logger"%>
<%@taglib uri="/i18n-1.0" prefix="i18n"%>
<%
	response.setContentType("text/html; charset=UTF-8");
	SysConfigBean sysbean = ApplicationHelper.getApplicationSysConfigBean(session);
	Connection conn = DBHelper.getConn();
	int menuId = StringHelper.isRequestParamEmptyInt(request, "menuId", 0);
	int categoryTypeId = StringHelper.isRequestParamEmptyInt(request, "categoryTypeId", CategoryTypeDef.NEW);
	List<CategoryBean> list = ApplicationHelper.getApplicationSubCategoryListById(session, categoryTypeId);
	int new_rsf_id = SequenceHelper.getSeqNextVal(conn, SequenceHelper.RSF_SEQ);
%>
<i18n:bundle baseName="i18n-ebizport" locale="<%=SessionFacade.getLocale(session)%>"/>
<html>
<head>
<meta name="keywords" content="<%=sysbean.getWebKey()%>" />
<meta name="description" content="<%=sysbean.getWebDesc()%>" />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=sysbean.getWebName()%></title>
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/global.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/admin.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<%=URLPath.CSS_DIR%>/uploadify.css" type="text/css" media="screen" />
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/jquery-1.9.1.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/jquery.uploadify.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/main.js"></script>
<script type="text/javascript" src="<%=URLPath.JS_DIR%>/ckeditor/ckeditor.js"></script>
<script src="<%=URLPath.JS_DIR%>/layer.js"></script>
<script type="text/javascript">
var uploadfileSuccess = false;
$(document).ready(function(){
	$("input[name='isimg']").on('click',function(){
	    if($(this).prop("checked") == true){
            $("#uploadimgtr").show();
	    } else {
	    	$("#uploadimgtr").hide();
	    } 
	});
	
	 $("#file_upload").uploadify({  //缩略图
		 'formData'  : {'uploadtype' : '1', 'infoId' : '<%=new_rsf_id%>'},
         'swf'       : '/js/uploadify.swf',
         'uploader'         : '/servlet/uploadFilesServlet',
         'buttonText' : '\u4e0a\u4f20\u65b0\u95fb\u7f29\u7565\u56fe',
         'auto' : false,
         'fileSizeLimit' : '3000KB',
         'fileTypeDesc' : '\u56fe\u7247\u6587\u4ef6',
         'fileTypeExts' : '*.gif; *.jpg; *.png',
         'multi' : false,
         'method' : 'post',
         'uploadLimit' : 1,
         'removeCompleted' : false,
         'queueID' : 'fileQueue',
         'progressData' : 'speed',
         'onUploadSuccess' : function(file, data, response){
        	 var fileName = file.name;
        	 var ext = fileName.substring(fileName.indexOf("."));
        	 document.myform.imgName.value = ext;
         }
     });
	 
	 $("#uploadfiles").on('click',function(){
		 $('#file_upload').uploadify('upload');
	 });
	 $("#clearUploadfiles").on('click',function(){
		 $('#file_upload').uploadify('cancel');
	 });
	 
	 
	 $("#attachment_upload").uploadify({  //附件
		 'formData'  : {'uploadtype' : '3', 'infoId' : '<%=new_rsf_id%>'},
         'swf'       : '/js/uploadify.swf',
         'uploader'  : '/servlet/uploadFilesServlet',
         'buttonText' : '\u9009\u62e9\u4e0a\u4f20\u9644\u4ef6',
         'auto' : false,
         'fileSizeLimit' : '10000KB',
         'multi' : true,
         'method' : 'post',
         'removeCompleted' : false,
         'queueID' : 'attachQueue',
         'progressData' : 'speed',
         'onUploadSuccess' : function(file, data, response){
        	 uploadfileSuccess = true;
         }
     });

	 
	 $("#addrsf").on('click',function(){
		 if(!checkFormItemNotNull()) return;
		 if(isEmpty(CKEDITOR.instances.ckeditorText.getData())){
			 layer.alert('\u5185\u5bb9\u4e0d\u80fd\u4e3a\u7a7a!', 8);
			 return; 
		 }
		 var imgName = document.myform.imgName.value;
		 if($("input[name='isimg']").prop("checked")==true&&isEmpty(imgName)){
			 layer.alert('\u8bf7\u4e0a\u4f20\u7f29\u7565\u56fe!', 8);
			 return;
		 }
		 <%if(categoryTypeId!=CategoryTypeDef.NEW){%>
		     $('#attachment_upload').uploadify('upload','*');
		 <%}%>
		 document.myform.submit();
	 });
	 CKEDITOR.replace('ckeditorText');
     <%
     if(RequestFacade.getSuccessFlag(request)){
          out.print("layer.alert('<"+request.getParameter("title")+"> \u53d1\u5e03\u6210\u529f!', 9);");	 
     }else if(!StringHelper.isEmpty(RequestFacade.getErrorMsg(request))){
    	  out.print("layer.alert('\u53d1\u5e03\u5931\u8d25,\u9519\u8bef\u4fe1\u606f:"+RequestFacade.getErrorMsg(request)+"!', 8);");
     }
     %>
});

	function checkFormItemNotNull() {
		var flag = true;
		$("select,input[notnull='true']").each(function() {
			if($(this).is("input")&&isEmpty($(this).val())
					||($(this).is("select")&&$(this).val()=='-1')
					||($(this).is("textarea")&&isEmpty($(this).val()))){
				layer.alert($(this).attr('desc')+'\u4e0d\u80fd\u4e3a\u7a7a!', 8);
				$(this).focus();
				flag=false;
				return false;
			}	
		});
		return flag;
	}
	
</script>
<style type="text/css">
a.but{
   background-color:#2ECC71;
   vertical-align:middle; 
   padding:5px 8px 5px 8px;
   text-align:center;
   line-height:40px;
   color:#FFF;
}
a.but:hover{
   background-color:#27AE60;
   cursor:hand;
}


</style>
</head>
<body>

<div class="admin-menu-nav">
   <ul >
     <li style="width:49.9%"><span class="menu-nav"><i18n:message key="now_position"/>:&nbsp;<%=MenuHelper.getMenuPath(session, menuId) %></span></li>
     <li style="width:50%"><span class="menu-button" id="addrsf"><i18n:message key="publish"/></span></li>
   </ul>   
</div>
<form name="myform" action="<%=URLPath.ADMIN_URL %>"  method="post" target="_self">
<input type="hidden" name="token" value="<%=request.getAttribute("token")%>">
<input type="hidden" name="cmd" value="AddRSF"/>
<input type="hidden" name="doNothing" value="N"/>
<input type="hidden" name="imgName" value=""/>
<input type="hidden" name="menuId" value="<%=menuId %>"/>
<input type="hidden" name="category" value="<%=categoryTypeId%>"/>
<input type="hidden" name="rsfid" value="<%=new_rsf_id%>"/>
<div class="mainDiv">
   <table class="dialogs">
      <tr>
         <td class="title"><i18n:message key="rsf.title"/>:</td>
         <td><input type="text" class="u-ipt-w300" name="title" value="" notnull="true" desc="<i18n:message key='rsf.title'/>"/></td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="rsf.auther"/>:</td>
         <td><input type="text" class="u-ipt-w90" name="author"  value="" notnull="true" desc="<i18n:message key='rsf.auther'/>"/></td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="rsf.source"/>:</td>
         <td><input type="text" class="u-ipt-w90" name="source"  value=""/></td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="rsf.keywords"/>:</td>
         <td><input type="text" class="u-ipt-w300" name="keywords"  value=""/>&nbsp;*<%="\u591a\u4e2a\u5173\u952e\u5b57\u4ee5\"|\"\u5206\u5272" %></td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="rsf.category"/>:</td>
         <td>
         <select name="subcategory" class="u-ipt-w180" style="height:28px" notnull="true" desc="<i18n:message key='rsf.category'/>">
            <option value="-1"><i18n:message key="please_select"/>
            <%
            if(list!=null&&list.size()>0){ 
                for(CategoryBean cBean:list){
             	   List<CategoryBean> subList = cBean.getChildCategoryBeans();
            %>
                   <optgroup label="<%=cBean.getName() %>">
                   <%
                   if(subList!=null&&subList.size()>0){
                	   for(CategoryBean subBean:subList){
                   %>
                       <option value="<%=subBean.getId() %>"><%=subBean.getName() %>
                   <%} }%>
                   </optgroup>
            <%} }%>
         </select>
         </td>
      </tr>
      <tr>
         <td class="title"><i18n:message key="istop"/>:</td>
         <td><input type="checkbox" name="istop" value="1"/><i18n:message key="yes"/></td>
      </tr>
      <tr  style="display:<%=(categoryTypeId!=CategoryTypeDef.NEW)?"none":""%>">
         <td class="title"><i18n:message key="image"/>:</td>
         <td><input type="checkbox" value="1" name="isimg"/>&nbsp;<i18n:message key="rsf.isuploadthumbnail"/></td>
      </tr>
      <tr id="uploadimgtr" style="display:none">
         <td class="title"></td>
         <td>
            <div id="fileQueue"></div>
            <input type="file" name="file_upload" id="file_upload" />
            <a href="javascript:;" id="uploadfiles" class="but"><i18n:message key="upload"/></a>&nbsp;
            <a href="javascript:;" id="clearUploadfiles" class="but"><i18n:message key="cancel"/></a>
         </td>
      </tr>
      <tr style="display:<%=(categoryTypeId!=CategoryTypeDef.NEW)?"":"none"%>">
         <td class="title"><i18n:message key="attachment"/></td>
         <td>
            <div id="attachQueue"></div>
            <input type="file" name="attachment_upload" id="attachment_upload" />
         </td>
      </tr>       
      <tr>
         <td class="title"><i18n:message key="rsf.content"/>:</td>
         <td><textarea id="ckeditorText" cols="80" name="content" rows="10"></textarea></td>
      </tr>
   </table>

</div>
</form>
</body>
</html>
<% DBHelper.closeConn(conn);%>